import Mock from "mockjs";

let { data } = Mock.mock({
  // 20条数据
  "data|55": [
    {
      // 商品种类
      goodsClass: "女装",
      // 商品Id
      "goodsId|+1": 10001,
      //商品名称
      goodsName: "@title(10)",
      //商品地址
      goodsAddress: "@county(true)",
      //商品等级评价★
      "goodsStar|1-5": "★",
      //商品图片
      goodsImg: "@Image('100x100','@color','小甜甜')",
      //商品售价
      "goodsSale|30-500": 30,
      name: "@cname",
    },
  ],
});

interface ParamsType {
  page: number;
  size: number;
}

interface RemoveType {
  goodsId: number;
}

class ProductServer {
  getData({ page, size }: ParamsType) {
    return new Promise((resolve) => {
      const reuslt = data.slice((page - 1) * size, page * size);
      resolve({
        status: 0,
        result: reuslt,
        count: data.length,
      });
    });
  }
  removeData({ goodsId }: RemoveType) {
    return new Promise((resolve) => {
      data = data.filter((item: any) => item.goodsId === !goodsId);
      resolve({
        status: 0,
        msg: "删除成功",
      });
    });
  }
  // addData() {}
}

const product = new ProductServer();
export default product;
